﻿<script language=JavaScript src='../inv/scripts/innovaeditor.js'></script>

<?
$pathdb="../upload";
$path = "../upload";
if (isset($_POST['butSaveLoai'])) {
	$subject=$_POST['txtName'];
	$subjecten=$_POST['txtNameen'];
	$shortdesc=$_POST['txtShortDescNew'];
	$desc=$_POST['txtDescNew'];
    $descvn=$_POST['txtDescNewvn'];
		$txtlast=$_POST['txtlast'];
	$status=($_POST['chkShow']!=''?1:0);
	$categories_id=$_POST['ddCat'];
	$subjectcn=$_POST['txtSource'];
	$ordered=(int)$_POST['txtSortorder'];
	$page = (int)$_POST['page'];

	$imageSmall=$_FILES['txtImage'];

	$err="";
	if($subject=="")
		$err =  "Xin nh&#7853;p tiêu &#273;&#7873;";
	
	//$ret=CheckUpload($_FILES["txtImage"],".jpg;.gif;.png;",500*1024,($_POST['id']!=''?0:1));
	$ret=CheckUpload($_FILES["txtImage"],".jpg;.gif;.png;.jpeg;",500*1024,0);
	if ($ret) $err.=$ret."<br>";
	
	if ($err=='')
	{
		// validate data
		if (!empty($_POST['id'])) {
			$oldid = $_POST['id'];
			$sql = "update news set news_subject='".$subject."',news_subjecten='".$subjecten."',news_shortcontent='".$shortdesc."',news_content='".$desc."',news_contentvn='".$descvn."',last_modified='".$txtlast."', status='".$status."', categories_id='".$categories_id."', news_source='".$subjectcn."', news_ordered=".$ordered." where news_id='".$oldid."'";
		}else {
			$sql = "insert into news (news_subject,news_subjecten,news_image,news_shortcontent,news_content,news_contentvn,last_modified,status,categories_id,date_added,news_source,news_ordered) values ('".$subject."','".$subjecten."','','".$shortdesc."','".$desc."','".$descvn."','".$txtlast."','".$status."','".$categories_id."',SYSDATE(),'".$subjectcn."','".$ordered."')";
		}
		//upload image
		
		if (mysql_query($sql,$con)) {
			if(empty($_POST['id'])) {
					$oldid = mysql_insert_id();
			}		
			$sqlUpdateField = "";
			
			if ($_POST['chkClear']=='')
			{
				// delete old image
			//	$news= GetNewsInfo($oldid);
			//	if (@file_exists($news['news_image'])) @unlink($news['news_image']);
				
				//upload new image
				$ext=GetFileExtention($_FILES['txtImage']['name']);
				if (MakeUpload($_FILES['txtImage'],"$path/news_s$oldid$ext"))
				{
					@chmod("$path/news_s$oldid$ext", 0777);
					$sqlUpdateField = " news_image='$pathdb/news_s$oldid$ext' ";
				}			
			}
			else 
			{
				// delete old image
				//$news= GetNewsInfo($oldid);
				//if (@file_exists($news['news_image'])) @unlink($news['news_image']);
				$sqlUpdateField = " news_image='' ";
			}
			
			// update image
			if($sqlUpdateField)
			{
				$sqlUpdate = "update news set $sqlUpdateField where news_id='".$oldid."'";
				mysql_query($sqlUpdate,$con);
			}
			
			//echo $sqlUpdateField." ".$oldid;exit(0);
		}	
		else {
			$err =  "<p align=center class='err'>Không th&#7875; c&#7853;p nh&#7853;t</p>";
		}
  	}
  	if ($err=='') echo '<script>window.location="index.php?act=news&cat='.$_REQUEST['cat'].'&page='.$_REQUEST['page'].'&code=1"</script>';
  	else echo "<p align=center class='err'>".$err."</p>";
} 
?>

<?
	if (isset($_GET['id'])) {
		$oldid=$_GET['id'];
		$page = $_GET['page'];
		$sql = "select * from news where news_id='".$oldid."'";
		if ($result = mysql_query($sql,$con)) {
			$row=mysql_fetch_array($result);
			$subject=$row['news_subject'];
			$subjecten=$row['news_subjecten'];
			$image=$row['news_image'];
			$categories_id = $row['categories_id'];
			$shortdesc=$row['news_shortcontent'];
			$desc=$row['news_content'];
            $descvn=$row['news_contentvn'];
			$status=$row['status'];
			$subjectcn=$row['news_source'];
			$ordered=$row['news_ordered'];
			$txtlast=$row['last_modified'];
		}
	}
?>
<style type="text/css">
<!--
.style1 {
	color: #FF0000;
	font-weight: bold;
}
-->
</style>


<form method="post" name="frmSubmit" enctype="multipart/form-data" action="index.php">
<input type="hidden" name="act" value="news_m">
<input type="hidden" name="id" value="<? echo $_REQUEST['id']; ?>">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#0069A8" width="100%" id="AutoNumber1">
  <tr>
    <td width="45%" class="title" align="center" height="20">S&#7917;a &#273;&#7893;i / C&#7853;p nh&#7853;t : </td>
  </tr>
  <tr>
    <td width="45%">
    <table border="0" cellpadding="2" bordercolor="#111111" width="100%" id="AutoNumber2" cellspacing="0">
<?  
if ($image!='')
{
	echo '<tr><td colspan=3 align="center"><img border="0" src="'.$image.'"></td></tr>';
}
?>		
	  <tr>
        <td width="20%" class="smallfont">
        <p align="right">Tiêu đề tiếng Anh</td>
        <td width="2%" class="smallfont" align="center">
        <font color="#FF0000">*</font></td>
        <td width="78%" class="smallfont">
		<INPUT value="<? echo $subject; ?>" TYPE="text" NAME="txtName" CLASS=textbox size="99"></td>
      </tr>
      	  <tr>
        <td width="20%" class="smallfont">
        <p align="right">Tiêu đề tiếng viet</td>
        <td width="2%" class="smallfont" align="center">
        <font color="#FF0000">*</font></td>
        <td width="78%" class="smallfont">
		<INPUT value="<? echo $subjecten; ?>" TYPE="text" NAME="txtNameen" CLASS=textbox size="99"></td>
      </tr>
	  	  <tr>
        <td width="20%" class="smallfont">
        <p align="right">MIN</td>
        <td width="2%" class="smallfont" align="center">&nbsp;</td>
        <td width="78%" class="smallfont">
		<INPUT value="<? echo $subjectcn; ?>" TYPE="text" NAME="txtSource" CLASS=textbox size="99"></td>
      </tr>
	  <tr>
        <td width="20%" class="smallfont">
        <p align="right">$ Hoặc USD (Tiếng Anh)</td>
        <td width="2%" class="smallfont" align="center">&nbsp;</td>
        <td width="78%" class="smallfont">
		<INPUT value="<? echo $desc; ?>" TYPE="text" NAME="txtDescNew" CLASS=textbox size="99"></td>
      </tr>
       <tr>
        <td width="20%" class="smallfont">
        <p align="right">đ Hoặc VNĐ (Tiếng Việt)</td>
        <td width="2%" class="smallfont" align="center">&nbsp;</td>
        <td width="78%" class="smallfont">
		<INPUT value="<? echo $descvn; ?>" TYPE="text" NAME="txtDescNewvn" CLASS=textbox size="99"></td>
      </tr>
      <tr>
        <td width="15%" class="smallfont">
        <p align="right">Hình &#7843;nh</td>
        <td width="1%" class="smallfont" align="center">&nbsp;
        </td>
        <td width="83%" class="smallfont">
		<INPUT TYPE="file" NAME="txtImage" CLASS=textbox size="34"><input type="checkbox" name="chkClear" value="ON">
		Xóa 
		b&#7887; hình<span class="style1">(Cập nhật hình cho mục Specials)</span></td>
      </tr>
      <tr>
        <td width="20%" class="smallfont" align="right">
        N&#7897;i dung Tiếng anh</td>
        <td width="2%" class="smallfont" align="center">&nbsp;</td>
        <td width="78%" class="smallfont">
			<textarea id="txtShortDescNew" name="txtShortDescNew" rows=4 cols=30><? echo $shortdesc;; ?></textarea>
			<script> //STEP 2: Replace the textarea (txtContent)
			var oEditShortDescNew = new InnovaEditor("oEditShortDescNew");
			oEditShortDescNew.arrStyle=[["BODY",false,"","font-family:Tahoma,Arial,Helvetica;font-size:10pt"]];
			oEditShortDescNew.width="100%";//You can also use %, for example: oEdit1.width="100%"
			oEditShortDescNew.height=400;		
			oEditShortDescNew.cmdAssetManager = "modalDialogShow('/inv/assetmanager/assetmanager.php',640,465)"; //Command to open the Asset Manager add-on.
			oEditShortDescNew.REPLACE("txtShortDescNew");//Specify the id of the textarea here
			</script>		
		</td>
      </tr>
      
	 <tr>
        <td width="20%" class="smallfont" align="right">
        N&#7897;i dungTiếng việt</td>
        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="78%" class="smallfont">
			<textarea id="txtlast" name="txtlast" rows=4 cols=30><? echo $txtlast; ?></textarea>
			<script> //STEP 2: Replace the textarea (txtContent)
			var oEditDescNew = new InnovaEditor("oEditDescNew");
			oEditDescNew.arrStyle=[["BODY",false,"","font-family:Tahoma,Arial,Helvetica;font-size:10pt"]];
			oEditDescNew.width="100%";//You can also use %, for example: oEdit1.width="100%"
			oEditDescNew.height=350;		
			oEditDescNew.cmdAssetManager = "modalDialogShow('/inv/assetmanager/assetmanager.php',640,465)"; //Command to open the Asset Manager add-on.
			oEditDescNew.REPLACE("txtlast");//Specify the id of the textarea here
			</script></td>
      </tr>
      
     <!-- <tr>
        <td width="20%" class="smallfont" align="right">
        N&#7897;i dung tiếng <b>Anh</b> </td>

        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="78%" class="smallfont">
			<textarea id="txtDescNew" name="txtDescNew" rows=4 cols=30><? echo $desc; ?></textarea>
			<script> //STEP 2: Replace the textarea (txtContent)
			var oEditDescNew = new InnovaEditor("oEditDescNew");
			oEditDescNew.arrStyle=[["BODY",false,"","font-family:Tahoma,Arial,Helvetica;font-size:10pt"]];
			oEditDescNew.width="100%";//You can also use %, for example: oEdit1.width="100%"
			oEditDescNew.height=350;		
			oEditDescNew.cmdAssetManager = "modalDialogShow('/inv/assetmanager/assetmanager.php',640,465)"; //Command to open the Asset Manager add-on.
			oEditDescNew.REPLACE("txtDescNew");//Specify the id of the textarea here
			</script>		
		</td>
      </tr>-->
<!--      <tr>
        <td width="15%" class="smallfont" align="right">
        Ngu&#7891;n tin</td>
        <td width="1%" class="smallfont" align="center">&nbsp;
        </td>
        <td width="83%" class="smallfont">
		<INPUT value="<? echo $source; ?>" TYPE="text" NAME="txtSource" CLASS=textbox size="53"></td>
      </tr>-->
      <tr>
        <td width="20%" class="smallfont" align="right">
        Không hi&#7879;n</td>
        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="78%" class="smallfont">
		<input type="checkbox" name="chkShow" value="ON" <? if ($status>0) echo 'checked' ?>></td>
      </tr>
      <tr>
        <td width="20%" class="smallfont" align="right">
        Thu&#7897;c danh m&#7909;c</td>
        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="78%" class="smallfont">
		<select size="1" name="ddCat">
<?
		$cats=GetListNewsCategoryAll();
		foreach ($cats as $cat)
		{
			if ($cat[0]==$categories_id)
				echo "<option value=".$cat[0]." selected>".$cat[1]."</option>";
			else
				echo "<option value=".$cat[0].">".$cat[1]."</option>";
		}
?>		
		</select></td>
      </tr>
      <tr>
        <td width="20%" class="smallfont" align="right">
        Th&#7913; t&#7921; s&#7855;p x&#7871;p</td>
        <td width="2%" class="smallfont" align="center">&nbsp;        </td>
        <td width="78%" class="smallfont">
		<INPUT value="<? echo $ordered; ?>" TYPE="text" NAME="txtSortorder" CLASS=textbox size="7"> 
		(s&#7889; nh&#7887; &#273;&#432;&#7907;c &#432;u tiên, có th&#7875; &lt;0)</td>
      </tr>
      <tr>
        <td width="20%" class="smallfont">
		<p align="right">
		<INPUT onclick="submitForm()" TYPE="submit" NAME="butSaveLoai" VALUE="C&#7853;p nh&#7853;t" CLASS=button>&nbsp;</td>
        <td width="2%" class="smallfont" align="center">&nbsp;		</td>
        <td width="78%" class="smallfont"><p align="left">&nbsp;<INPUT TYPE="reset" CLASS=button value="Nh&#7853;p l&#7841;i"></td>
      </tr>
    </table>
    </td>
  </tr>
  </table>
</form>